﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    public class SCSolution : SCTreeViewItem<SPSolution>
    {
        public static readonly DependencyProperty DeployedProperty = DependencyProperty.Register("Deployed", typeof(bool), typeof(SCSolution));
        public bool Deployed {
            get { return (bool)GetValue(DeployedProperty); }
            set { SetValue(DeployedProperty, value); }
        }

        public SCSolution(SCTreeViewItem parent, SPSolution solution)
            : base(parent, solution)
        {
            Header = solution.Name;
            Deployed = solution.Deployed;
            Expanded += new RoutedEventHandler(SCSolution_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCSolution_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (!item.ItemsSource.OfType<SCProperties>().Any())
            {
                ItemsSource = new[] { new SCProperties(this, SPObject.Properties) as TreeViewItem };
            }
        }
    }
}
